package com.lyf.learn.atsgg.spring.transaction.service;

import com.lyf.learn.atsgg.spring.transaction.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @AUTHOR LYF
 * @DATE 2022/5/26
 * @VERSION 1.0
 * @DESC
 */
@Service
public class TransferServiceImpl implements TransferService{
    @Autowired
    AccountDao accountDao;
  //  @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.REPEATABLE_READ)
    @Transactional
    @Override
    public void transfer(String name1, String name2, Integer money) {
        accountDao.decrAccount(name1,money);
        // 模拟异常
        int i = 10/0;

        accountDao.addAccount(name2,money);
    }
}
